/*
 * 
 * 版    本： 1.0 
 * 类    名： UserManage
 * 文  件  名： UserManage.java
 * 
 * 
 * 描    述： 管理用户信息
 * 
 */
package com.aptech.restrant.Controller;



import com.aptech.restrant.Model.AdminBean;
import com.aptech.restrant.Model.UserBean;
import db.DBProOp;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserManage {
	/**
	 * 验证管理员登陆
	 * @param username
	 * @param password
	 * @return 返回Account model类
	 */
	public static UserBean checkUser(String username, String password) {
		DBProOp dbo = new DBProOp();
		UserBean account=new UserBean();
		dbo.initDBOp("usr_login", 4, 0);
		try {
			//System.out.println(username +"   "+ password);
			dbo.setParaString(1, username);
			dbo.setParaString(2, password);
			dbo.setRetInt(3);
			dbo.setRetInt(4);
			dbo.runProWithNoRS();
			account.setUserID(dbo.getRetInt(4));
			account.setUserName(username);
			account.setUserPass(password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			dbo.close();
			}
		return account;			
	}
	


	/**
	 * 取得一个用户的信息
	 * @param id 用户id
	 * @return Users类对象
	 */
	public static UserBean getUsers(int id){
		UserBean users = new UserBean();
		ResultSet rs = null;
		DBProOp dbo = new DBProOp();
		dbo.initDBOp("usr_get_usrdetail", 1, 0);
		dbo.setParaInt(1, id);
		dbo.runPro();
		rs = dbo.getRs();
		try {
			if(rs.next())
			{
				users.setUserID(id);
				users.setUserRealName(rs.getString(2));
				//System.out.println(rs.getString(2));
				users.setUserSex(rs.getString(3));
				users.setUserMail(rs.getString(6));

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return users;
	}
}
